#!/bin/csh -f
### cd to vasp dir, get XYZ.cont, and project coords on current
### parameters

set vaspalloy=/home/alloy.db/
set tdir=/home/alloy.db/BMgRu/deca
set par=
set figopt=()
set fig=
set swapdef="2,1,3"
set tname=""
set swap=
while ("$1" != "")
    switch ($1)
	case -adir:
	    shift
	    set tdir=$vaspalloy/$1
	breaksw
	case -par:
	    set par=1
	breaksw
	case -h:
	    echo "Synopsis: getxyzcont -adir ALLOYDIR [-par] [-fig figopts]"
	    exit
	breaksw
	case -fig:
	    set fig=1
	breaksw
	case -swap:
	    shift
	    set swap=1
	    set swapdef=$1
	breaksw
	default:
	    if(-f $1) then 
		set tname=$1
	    else
		set figopt=($figopt $1)
	    endif
	breaksw
    endsw
    shift
end
if($tname == "" || ! -d $tdir/$tname) then
    echo "$tdir/$tname does not exist"
    exit
endif
set cdir=`pwd`
cd $tdir/$tname
set swp=`head -4 XYZ | awk '$0~/swapped/{print "1"}'`
if(! -f XYZ.cont) then 
    $mgtools/shbin/cont2xyz > XYZ.cont
endif
if($swap != "") set swp=1
if($swp != "") then
    echo "Swapped XYZ.cont -> xyz.$tname"
    $mgtools/shbin/swapcolsxyz $swapdef XYZ.cont > $cdir/xyz.$tname
else
    echo "XYZ.cont -> xyz.$tname"
    cp XYZ.cont $cdir/xyz.$tname
endif
cd $cdir
if(-f xyz.$tname) then
    fig $tname > fig.rep
    xyz2xyz xyz.fig xyz.$tname > xyz.reg
    if($par != "") then
	xyz2para $tname xyz.reg > drel.$tname
	para2para copa.apa
	cp INPUT/ap.def ap.def.$tname
	echo "Created ap.def.$tname"
    else if ($fig != "") then
	fig $tname -xyz xyz.reg $figopt
    endif
else
    echo "Dont have xyz.$tname"
endif
##
